//初始化加载折线图和表格
$(document).ready(function () {
	siteKey = $("#siteKey").val();
	type = $("#hdtype").val();
	if(siteKey=="" || type==""){
		var str = "<div class='em100 whitediv' id='zhanwushuju'><div class='em25'></div><div class='backyellow'>&nbsp;&nbsp;暂无数据！请选择场所</div></div>"
		$("#myForm .widthall .chartdiv").children("div[id!='zhanwushuju']").hide();
		$("#myForm .widthall .xiangxidiv").children("div[id!='zhanwushuju']").hide();
		$("#myForm .widthall .chartdiv").html(str);
		$("#myForm .widthall .xiangxidiv").html(str);
		
	}else{
		getIndexOrder();
	}
})

//时间段时间控件
$( function () {
	var endDate=new Date();//当前时间
	endDate=endDate.getFullYear()+"-"+(endDate.getMonth()+1)+"-"+endDate.getDate();
	var startDate=(new Date());
	startDate.setDate(startDate.getDate()-30);//前一个月时间
	startDate=startDate.getFullYear()+"-"+(startDate.getMonth()+1)+"-"+startDate.getDate();
	siteKey = $("siteKey").val();
 	if(siteKey!=""){
	    var dateObj = {
	        theme: 'ta', // 日期选择器TA主题
	        autoCommit: true, //自动提交，完成日期初始化，以及图表的展示拉取
	        isTodayValid: true,
	        startDate: startDate,
	        endDate: endDate,
	        needCompare: true,
	        startCompareDate: '',
	        endCompareDate: '',
	        singleCompare: false,
	        defaultText: ' 至 ',
	        autoSubmit: false,
	        shortOpr: false,
	        target: 'datePicker',
	        calendars: 2,
	        inputTrigger: 'input_trigger',
	        compareCheckboxId: false,
	        success: function (obj) {
	            if (($("#txtspan").val().split("_"))[1] == "0" || $("#needCompare").val() == "1")//处于如期选择框时
	            {
	                loadChart($("#hdtype").val());
	            }
	        }
	    };
	    new pickerDateRange("date", dateObj)
 	}
})

function loadPaiHang(siteId, type) {}
//加载折线图表取XY轴
function  getXY(avgList) {
	var dataRe="";
		for(var i=0;i<avgList.length;i++){
  				dataRe=dataRe + avgList[i]+",";
		}
	dataRe=dataRe.substring(0,dataRe.length-1);
	return dataRe
}

var zhibiaodanwei = "";
var indexname ="";
//场所名称
var siteName = "";

var siteTypeName = "";
//加载折线图表
 function loadChart(type) {
	 showLoading();
	//指标显示底色
	 zhibiaoCss(type);
	 //获取指标名称
     indexname = array[parseInt(type)];
     //获取指标单位
	 zhibiaodanwei = arraydanwei[parseInt(type)];
     var data = [];
     var xsis = [];
     var from = $('#startDate').val();
     var to = $('#endDate').val();
     var siteId= $("#siteKey").val();
     var tubiao = "tubiao1";
     var span = $("#txtspan").val();
     shijianCss(span);
     var myChart = echarts.init(document.getElementById(tubiao));
   	$.ajax( {
   		type : "GET",
   		contentType:"application/json",
   		dataType : 'json',
   		url: "squareWeatherGraph",
   		data: { from: from, to: to,type: type, span: span, siteId: siteId },
   		async: true,
   		success : function(ret) {
   			var width = $("#tubiao1").width();
			var height = $("#tubiao1").height();
			var titleOffens = width*7.6/100;
			var dataZoomY = height*(1-19/100);
			var toolboxX = width*80/100;
			var legendY = height*4/100;
			var toolboxY = height*4/100;
			//获取当前时间
			var date = new Date;
			var today = timeFormat(date);
			siteTypeName = ret.siteTypeName;
			//保存图片的名称
			var toolboxName = $("#titles").val()+'-各类天气指标分布'+today;
			siteName = ret.siteName
   			var  result = ret.result;//返回数据集
   			var tubiaoDate=result.getTubiaoDate;//图表一数据
   			var pieData=result.pieData;//饼图数据
   			var weekWeaherDate= result.weekWeaherDate//天气星期对比分析
   			var historyWeatherData= result.historyWeatherData//历史指标天气分析
   			var stadubiao = result.stadubiao;
   			var endtubiao = result.endtubiao;
   			var siteN = result.siteN;
			
			var titContext="数据说明："+siteTypeName+"各类天气指标分布"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
			var biaogeshuoming = "数据说明："+siteTypeName+"各类天气指标分布"+"<br/>"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
					+"场所名称："+siteN+"<br/>"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
					
			$("#biaogeshuoming").html(biaogeshuoming);
   			var xsis = ['晴天','阴天 ','雨天','雪天']; 
   			var dateStr=""//数据data
   			var titName=['日平均客流','节假日平均客流','工作日平均客流'];//表题
   			var avgList=tubiaoDate.avgList;
   			var markLinePrecision = 0;
   			dateStr=dateStr+"{name:'日平均客流',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'bar',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:false,position:'top'}}},data:[" +avgList + "]}"+",";
   			var WeekList=tubiaoDate.WeekList;
   			dateStr=dateStr+"{name:'节假日平均客流',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'bar',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:false,position:'top'}}},data:[" +WeekList + "]}"+",";
   			var workList=tubiaoDate.workList;
   			dateStr=dateStr+"{name:'工作日平均客流',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'bar',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:false,position:'top'}}},data:[" +workList + "]}"+",";
	   		
   			xsis = eval(xsis);
   			titName= eval(titName);
   			data = eval("["+dateStr+"]");

   			var  option = {
			title : {
 		      text: titContext,
 		      y:'bottom',
 		      x:titleOffens,
 		      textStyle:{
 		       	fontSize: 12,
   		        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
   		        fontWeight:'normal'
 		    	}		
 		    },
 		   tooltip: {
   				trigger: 'axis',
   				backgroundColor: 'rgba(0,0,0,0.7)',
   				position: function(p) {
   					return [p[0] + 10, p[1] - 10];
   				},
				formatter: function(params, ticket, callback){
					
					var returnstr = "";
						var time = params[0][1];
							returnstr = "<tr>"+siteName+"<br/>"+time+"</tr>";
						for (var i=0; i<params.length; i++) {
							var a = params[i][0];
							var c = params[i][2];
							c = addKannma(c);
							if (c == '') {
								c = 0;
							}
							returnstr = returnstr +  "<tr><td>"+a+"："+"</td><td style='text-align: right;'>"+c+"</td></tr>";
							
						};
						var table = "<table>"+returnstr+"</table>"
						return table;
					}
//   				formatter: siteName+"<br/>{a}:{b}<br/>"+indexname+":{c}"
//					formatter: function(params, ticket, callback) {
////					console.log(params);
//					var a = params[0];
//   		   			var b = params[1];
//   					var c = params[2];
//					var seriesIndex = params.seriesIndex;
//					var dataIndex = params.dataIndex;
//					
//   					c = addKannma(c);
//   					if (c == '') {
//   						c = 0;
//   					}
//					return stadubiao+"~"+endtubiao+"<br/>"+a+":("+b+")<br/>"+siteName+"<br/>"+indexname+":"+c
//   				}
   			},
			legend: {
				data:titName,
				y:legendY
				},
			dataZoom: {
   		        show: true,
   		        y:dataZoomY 
   		    },
			grid:{
   				x:'7.6%',
   				y:'11%',
   				y2:'27%',
   				borderWidth: gridBorderWidth,
				borderColor:'#EEE'
   			},
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            magicType : {show: true, type: ['line', 'bar']},
		            restore : {show: true},
		            saveAsImage : {show: true,name:toolboxName}
		        },
				x:toolboxX,
				y:toolboxY
		    },
		    calculable : true,
		    xAxis : [
		        {
		        	name : '天气',
		        	boundaryGap: true,//两端空白策略
		        	allowDecimals :true,//使用小数
		            type : 'category',
		            splitLine: {show: xAxisSplitLine,
					lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		            splitArea:{
						show:xAxissplitArea,
						areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
					},
		            data : xsis,
		            axisTick:{
						show:true,
						interval:0
					}
		        }
		    ],
		    yAxis : [
		        {
					axisLabel:{
							formatter: function (value) {
			            		if(value > 10000){
			            			return (value/10000)+'万';
			            		}else{
			            			return value + '';
			            		}
							}
						},
		        	splitLine: {
						show: yAxisSplitLine,
						lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
		        	splitArea:{
						show:yAxissplitArea,
						areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
					},
		        	name : indexname+'('+zhibiaodanwei+')',
		            type : 'value'
		        }
		    ],
		    series : data
		};
   			//改变窗口大小使图标自适应窗口显示
   			window.onresize = function () {
   				myChart.resize();
   			}
   			//加载折线图
   			myChart.setOption(option);
   			//加载表格
   			loadChartTable(tubiaoDate);
   			//加载饼图
   			loadpieGraph(pieData,stadubiao,endtubiao,siteN);
   			//加载天气星期对比分析
   			loadweekWeaherGraph(weekWeaherDate,stadubiao,endtubiao,siteN);
   			//历史指标天气分析折线图
   			loadhistoryWeatherGraph(historyWeatherData,type,stadubiao,endtubiao,siteN);
   			hideLoading();
   		},
		error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
   	})
}
 
 function loadhistoryWeatherGraph(historyWeatherData,type,stadubiao,endtubiao,siteN){
	 var xsisRe="";//X轴
	 var dataData="";//数据线
	 var dataAvg="";//数据线
	 var titName=["总客流"];//表题,"工作日平均客流
	
	 var tit="数据说明："+siteTypeName+"指标趋势分析"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
	var historyWeathershuoming = "数据说明："+siteTypeName+"指标趋势分析"+"<br/>"
			+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
			+"场所名称："+siteN+"<br/>"
			+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
	 $("#historyWeathershuoming").html(historyWeathershuoming);
	 var width = $("#historyWeatherDataGraph").width();
	var height = $("#historyWeatherDataGraph").height();
	var titleOffens = width*7.6/100;
	var dataZoomY = height*(1-19/100);
	var toolboxX = width*81.5/100;
	var legendY = height*4/100;
	var toolboxY = height*4/100;
	titContext = tit;
	//获取当前时间
	var date = new Date;
	var today =  timeFormat(date);
	//保存图片的名称
	var toolboxName = $("#titles").val()+'-趋势分析'+today;
		 
	 var data=historyWeatherData.data;
	 var avg=historyWeatherData.avg;
	 for(var n=0;n<data.length;n++){
		 
		 var categoryname="";
		 categoryname=data[n].categoryName;
		 xsisRe=xsisRe+data[n].datatime+'\n'+((data[n].categoryName==null)?'无':categoryname.substring(0, 1))+","
		 indexNamefiled = getOrderField(type);
		 var datetemp = (getObjectVlue(data[n],indexNamefiled))==null?0:(getObjectVlue(data[n],indexNamefiled));
		 dataData=dataData+datetemp+",";
	 }
	 xsisRe=xsisRe.substring(0,xsisRe.length-1);
	 xsis=xsisRe.split(",");
	 dataData=dataData.substring(0,dataData.length-1);
	 /**
	 * 横坐标只有一个值时显示为柱状图，柱状宽度最大为40
	 */
	 var lineType = 'line';
	 if(xsis.length ==1){
		 lineType = 'bar';
	 }else{
		 lineType = 'line';
	 }
	 var barMaxWidthn = 40;
	 var markLinePrecision = 0;
	 dateGraph="{name:'总客流',smooth: smoothType,type:lineType,barMaxWidth:barMaxWidthn,itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dataData + "],markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]}}";
	 dateGraph = eval("["+dateGraph+"]");
	 var myChart = echarts.init(document.getElementById("historyWeatherDataGraph"));
	 var  option = {
				 tooltip: {
					trigger: 'axis',
					backgroundColor: 'rgba(0,0,0,0.7)',
					position: function(p) {
						return [p[0] + 10, p[1] - 10];
					},
//					formatter: siteName+"<br/>{a}:{b}<br/>"+indexname+":{c}"
					formatter: function(params, ticket, callback){
						console.log(params);
						var returnstr = "";
						
						var b = params[0][1];
						b = b.split("\n");
						returnstr = b[0]+"("+b[1]+")"
						console.log(b);
						var c = params[0][2];
						c = addKannma(c);
						if (c == '') {
							c = 0;
						}
						returnstr = returnstr + '<br/>' + siteName + ' : ' + c;
							
						return returnstr;
					}
				},
				title : {
		   		      text: titContext,
		   		      y:'bottom',
		   		      x:titleOffens,
		   		      textStyle:{
		   		        fontSize: 12,
		   		        color: '#666',
						fontFamily:'微软雅黑, 兰亭细黑, 宋体',
		   		        fontWeight:'normal'
		   		    	}		
		   		    },
		   		 dataZoom: {
		   		        show: true,
		   		        y:dataZoomY 
		   		    },
		   		 grid:{
		   				x:'7.6%',
		   				y:'11%',
		   				y2:'27%',
		   				borderWidth: gridBorderWidth,
						borderColor:'#EEE'
		   			},
//				legend: {
//					data:titName,
////					y:legendY
//				},
				toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            magicType : {show: true, type: ['line', 'bar']},
			            restore : {show: true},
			            saveAsImage : {show: true,name:toolboxName}
			        },
			        x:toolboxX,
//			        y:toolboxY
			    },
				calculable : true,
				xAxis : [
					{
						name : '日期'+'('+'日'+')',
				    	boundaryGap: true,//两端空白策略
				    	allowDecimals :true,//使用小数
				        type : 'category',
				        splitLine: {show: xAxisSplitLine,
						lineStyle:{
								 color: ['#EEE'],
								
							}},//不显示竖线
			            splitArea:{
							show:xAxissplitArea,
							areaStyle:{
									color: [
							        'rgba(250,250,250,0.1)',
							        'rgba(200,200,200,0.1)']
								}
						},
				        data : xsis,
				        axisTick:{
							show:true,
							interval:0
						}
				    }
				],
				yAxis : [
				    {
						axisLabel:{
							formatter: function (value) {
			            		if(value > 10000){
			            			return (value/10000)+'万';
			            		}else{
			            			return value + '';
			            		}
							}
						},
				    	splitLine: {
						show: yAxisSplitLine,
						lineStyle:{
							 color: ['#EEE'],
							
						}},//不显示竖线
			        	splitArea:{
							show:yAxissplitArea,
							areaStyle:{
								color: [
						        'rgba(250,250,250,0.1)',
						        'rgba(200,200,200,0.1)']
							}
						},
				    	name : indexname+'('+zhibiaodanwei+')',
				        type : 'value'
			        }
				],
				series : dateGraph
	 };
	 //改变窗口大小使图标自适应窗口显示
	 window.onresize = function () {
	 	myChart.resize();
	 }
	 //加载折线图
	 myChart.setOption(option);
	 //历史指标天气分析图表
	 loadhistoryWeatherTable(historyWeatherData,type);
 }
 
function loadhistoryWeatherTable(historyWeatherData,type){
	var indexname = array[parseInt(type)];
	//计算table列宽
	var rowNum = 4;
	var rowWidth = 0;
	rowWidth = ((100-5.4)/(1+rowNum));
	
	var data=historyWeatherData.data;
	var strTr= "<tr><th class='xykongbai'></th><th class='xyxuhao'>序列</th>" +
			"<th style='width: "+rowWidth+"%;'>日期</th><th style='width: "+rowWidth+"%;'>星期</th>" +
			"<th style='width: "+rowWidth+"%;'>天气</th><th style='width: "+rowWidth+"%;'>"+indexname+"</th><th class='xykongbai'></th></tr>";
	for(var i=0; i<data.length;i++){
		var indexNamefiled = getOrderField(type);
		var datetemp = (addKannma(getObjectVlue(data[i],indexNamefiled)))==null||(addKannma(getObjectVlue(data[i],indexNamefiled)))==""?"0":(addKannma(getObjectVlue(data[i],indexNamefiled)));
		strTr=strTr+"<tr><td class='xykongbai'></td><td class='xyxuhao'>"+(i+1)+"</td><td>"+data[i].datatime+"</td><td>"+getWeek(data[i].datatime)+"</td><td>"+((data[i].categoryName==null)?'无':data[i].categoryName)+
		"</td><td>"+datetemp+"</td><td></td></tr>";
	}	
	var html="<table  class='indextable xyliebiao widthall' id=\"tableOut1\">"+strTr+"</table>";
	$("#hdtable").val(html);
	showtablecomp(1);
}
 
function getWeek(dateStr){
	 arys1=dateStr.split('-'); 
	 var ssdate=new Date(arys1[0],parseInt(arys1[1]-1),arys1[2]);   
	 if(ssdate.getDay()==0){
		 return "星期天"
	 }else if(ssdate.getDay()==1){
		 return "星期一"
	 }else if(ssdate.getDay()==2){
		 return "星期二"
	 }else if(ssdate.getDay()==3){
		 return "星期三"
	 }else if(ssdate.getDay()==4){
		 return "星期四"
	 }else if(ssdate.getDay()==5){
		 return "星期五"
	 }else if(ssdate.getDay()==6){
		 return "星期六" 
	 }
}

 function showtablecomp(pageindex){
	    var ret=$("#hdtable").val();
	    var size=parseInt($("#hdtablesize").val());
	    var index=ret.indexOf("</th></tr>");
	    var head=ret.substr(0,index+10);
	    var index2=ret.indexOf("</table>");
	    var foot=ret.substr(index2,ret.length-1);
	    ret=ret.substring(index+10,index2);
	    var rets=ret.split("</tr>");
//	    if((rets.length-1)<=size)
//	    {
//	        $("#divfanye").css("display","none");
//	    }else{
//	        $("#divfanye").css("display","");
//	    }
	    if(pageindex==1){
	        if((rets.length-1)%size==0){
	            $("#allpage").text(parseInt((rets.length-1)/size));
	        }else{
	            $("#allpage").text(parseInt((rets.length-1)/size+1));
	        }
	    }
	    $("#divfanye img[src='images/fanye2_left.png']").parent("div").show();
		 $("#divfanye img[src='images/fanye2_right.png']").parent("div").show();
	     if (parseInt($("#allpage").text()) == 1) {
	    	 	$("#divfanye img[src='images/fanye2_left.png']").parent("div").hide();
	    	 	$("#divfanye img[src='images/fanye2_right.png']").parent("div").hide();
			}
		if (pageindex == 1) {
			$("#divfanye img[src='images/fanye2_left.png']").parent("div").hide();
		}
		if (pageindex == parseInt($("#allpage").text())) {
			$("#divfanye img[src='images/fanye2_right.png']").parent("div").hide();
		}
	    
	    var sindex=(pageindex-1)*size;
	    var eindex=pageindex*size-1;
	    if(eindex>rets.length-1){
	        eindex=rets.length-1;
	    }
	    var ret="";
	    for(i=sindex;i<=eindex;i++)
	    {
	        ret+=rets[i]+"<tr/>";
	    }
	    $("#historyWeatherDataGraphtable").html(head+ret+foot);
	    $("#curpage").text(pageindex);
	}
 
 //翻页
 function gotopagecomp(i){
//	    var curpage=parseInt($("#curpage").text());
//	    var allpage=parseInt($("#allpage").text());
//	    if(type==-1)
//	    {
//	        if(curpage!=1){
//	            curpage--;
//	        }
//	    }
//	    else if(type==1){
//	        if(curpage!=allpage){
//	            curpage++;
//	        }
//	    }
//	    else if(type==2)
//	    {
//	        if(parseInt($("#txtpages").val())<=allpage&&parseInt($("#txtpages").val())>=1){
//	            curpage=parseInt($("#txtpages").val());
//	        }
//	        else
//	        {
//	            alert("提示","超出范围！");
//	        }
//	    }
//	    else if(type==3){
//	        curpage=allpage;
//	    }
// 纯数字正则
		var numRule = /(^\d*$)|(^\S+\s+\S+$)/;
		var j = 1;
		var maxPage = parseInt($("#allpage").html());
		// 首页
		if (i == 0) {
			j = 1;
		}
		// 下一页
		else if (i == 1) {
			j = parseInt($("#curpage").html()) + 1;
		}
		// 上一页
		else if (i == -1) {
			j = parseInt($("#curpage").html()) - 1;
		}
		// 跳转
		else if (i == 2) {
			var gotoPage = $("#txtpages").val().trim();
			if (gotoPage == "") {
				j = 1;
			} else if (!gotoPage.match(numRule)) {
				j == 1
			} else {
				j = parseInt(gotoPage);
			}
		}
		// 尾页
//		else if (i == -1) {
//			j = maxPage;
//		}
		if (j < 1) {
			j = 1;
		}
		if (j > maxPage) {
			j = maxPage;
		}
//		$("#gotoPage").val(j);
	    showtablecomp(j);
	}
 
 function loadweekWeaherGraph(weekWeaherDate,stadubiao,endtubiao,siteN){
	var tit="数据说明："+siteTypeName+"指标天气&星期综合分析"+"\n"
					+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
					+"场所名称："+siteN+"\n"
					+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
	var weekWeathershuoming = "数据说明："+siteTypeName+"指标天气&星期综合分析"+"<br/>"
			+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"<br/>"
			+"场所名称："+siteN+"<br/>"
			+"指标名称："+indexname+"（"+zhibiaodanwei+"）";
	$("#weekWeathershuoming").html(weekWeathershuoming);
	var width = $("#weekWeatherGraph").width();
	var height = $("#weekWeatherGraph").height();
	var titleOffens = width*7.6/100;
	var dataZoomY = height*(1-19/100);
	var toolboxX = width*81.5/100;
	var legendY = height*4/100;
	var toolboxY = height*4/100;
	titContext = tit;
	//获取当前时间
	var date = new Date;
	var today = timeFormat(date);
	//保存图片的名称
	var toolboxName = $("#titles").val()+'-天气&星期综合分析'+today;
	
	 var dateStr1="";
	 var dateStr2="";
	 var dateStr3="";
	 var dateStr4="";
	 var zhouyi=weekWeaherDate.zhouyi;
	 dateStr1=dateStr1+zhouyi[0]+",";
	 dateStr2=dateStr2+zhouyi[1]+",";
	 dateStr3=dateStr3+zhouyi[2]+",";
	 dateStr4=dateStr4+zhouyi[3]+","; 
	 var zhouer=weekWeaherDate.zhouer;
	 dateStr1=dateStr1+zhouer[0]+",";
	 dateStr2=dateStr2+zhouer[1]+",";
	 dateStr3=dateStr3+zhouer[2]+",";
	 dateStr4=dateStr4+zhouer[3]+","; 
	 var zhousan=weekWeaherDate.zhousan;
	 dateStr1=dateStr1+zhousan[0]+",";
	 dateStr2=dateStr2+zhousan[1]+",";
	 dateStr3=dateStr3+zhousan[2]+",";
	 dateStr4=dateStr4+zhousan[3]+","; 
	 var zhousi=weekWeaherDate.zhousi;
	 dateStr1=dateStr1+zhousi[0]+",";
	 dateStr2=dateStr2+zhousi[1]+",";
	 dateStr3=dateStr3+zhousi[2]+",";
	 dateStr4=dateStr4+zhousi[3]+","; 
	 var zhouwu=weekWeaherDate.zhouwu;
	 dateStr1=dateStr1+zhouwu[0]+",";
	 dateStr2=dateStr2+zhouwu[1]+",";
	 dateStr3=dateStr3+zhouwu[2]+",";
	 dateStr4=dateStr4+zhouwu[3]+","; 
	 var zhouliu=weekWeaherDate.zhouliu;
	 dateStr1=dateStr1+zhouliu[0]+",";
	 dateStr2=dateStr2+zhouliu[1]+",";
	 dateStr3=dateStr3+zhouliu[2]+",";
	 dateStr4=dateStr4+zhouliu[3]+","; 
	 var zhouri=weekWeaherDate.zhouri;
	 dateStr1=dateStr1+zhouri[0]+",";
	 dateStr2=dateStr2+zhouri[1]+",";
	 dateStr3=dateStr3+zhouri[2]+",";
	 dateStr4=dateStr4+zhouri[3]+","; 

		 
	 dateStr1=eval("["+dateStr1+"]");
	 dateStr2=eval("["+dateStr2+"]");
	 dateStr3=eval("["+dateStr3+"]");
	 dateStr4=eval("["+dateStr4+"]");
	 var xsis = ['星期一','星期二 ','星期三','星期四','星期五','星期六','星期日']; 
	 var markLinePrecision = 0;
	var date1="{name:'晴',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'line',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dateStr1 + "]}"+","+
	"{name:'阴',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'line',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dateStr2 + "]}"+","+
	"{name:'雨',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'line',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dateStr3 + "]}"+","+
	"{name:'雪',smooth: smoothType,markLine: {precision:markLinePrecision,data: [{type: 'average',name: '平均值'}]},type:'line',itemStyle:{ normal:{color:'#feab41'}},itemStyle:{normal:{label:{show:"+getShow(xsis)+",position:'top'}}},data:[" +dateStr4 + "]}"+",";
	titName=['晴','阴','雨','雪'];	
	 data = eval("["+date1+"]");
	  var myChart = echarts.init(document.getElementById("weekWeatherGraph"));
	 var  option = {
			 title : {
		      text: titContext,
		      y:'bottom',
		      x:titleOffens,
		      textStyle:{
		        fontSize: 12,
   		        color: '#666',
				fontFamily:'微软雅黑, 兰亭细黑, 宋体',
   		        fontWeight:'normal'
		    	}		
		    },
		    dataZoom: {
		        show: true,
		        y:dataZoomY 
		    },
		    tooltip: {
   				trigger: 'axis',
   				backgroundColor: 'rgba(0,0,0,0.7)',
   				position: function(p) {
   					return [p[0] + 10, p[1] - 10];
   				},
//   				formatter: siteName+"<br/>{b}:{a}<br/>"+indexname+":{c}"
				formatter: function(params, ticket, callback){
					console.log(params);
					var returnstr = "";
					var time = params[0][1];
					returnstr = siteName + '<br/>' + time;	
					
					
					for (var i = 0; i < params.length; i++) {
						var a = params[i][0];
						var c = params[i][2];
						c = addKannma(c);
						if (c == '') {
							c = 0;
						}
						returnstr = returnstr +  "<tr><td>"+a+"："+"</td><td style='text-align: right;'>"+c+"</td></tr>";
					};
					var table = "<table>"+returnstr+"</table>"
					return table;
				}
   			},
			grid:{
				x:'7.6%',
				y:'11%',
				y2:'27%',
				borderWidth: gridBorderWidth,
				borderColor:'#EEE'
			},
		    toolbox: {
		        show : true,
		        feature : {
		            mark : {show: true},
		            magicType : {show: true, type: ['line', 'bar']},
		            restore : {show: true},
		            saveAsImage : {show: true,name:toolboxName}
		        },
		        x:toolboxX,
//		        y:toolboxY
		    },
			legend: {
				data:titName,
//				y:legendY
				},
	    calculable : true,
	    xAxis : [
	        {
	        	name : '星期',
	        	boundaryGap: true,//两端空白策略
	        	allowDecimals :true,//使用小数
	            type : 'category',
	            splitLine: {show: xAxisSplitLine,
				lineStyle:{
						 color: ['#EEE'],
						
					}},//不显示竖线
	            splitArea:{
					show:xAxissplitArea,
					areaStyle:{
							color: [
					        'rgba(250,250,250,0.1)',
					        'rgba(200,200,200,0.1)']
						}
				},
	            data : xsis,
	            axisTick:{
					show:true,
					interval:0
				}
	        }
	    ],
	    yAxis : [
	        {
				axisLabel:{
							formatter: function (value) {
			            		if(value > 10000){
			            			return (value/10000)+'万';
			            		}else{
			            			return value + '';
			            		}
							}
						},
	        	splitLine: {
					show: yAxisSplitLine,
					lineStyle:{
						 color: ['#EEE'],
						
					}},//不显示竖线
	        	splitArea:{
					show:yAxissplitArea,
					areaStyle:{
						color: [
				        'rgba(250,250,250,0.1)',
				        'rgba(200,200,200,0.1)']
					}
				},
	        	name : indexname+'('+zhibiaodanwei+')',
	            type : 'value'
	        }
	    ],
	    series : data
	};
	//改变窗口大小使图标自适应窗口显示
		window.onresize = function () {
			myChart.resize();
		}
		//加载折线图
		myChart.setOption(option);
		//加载图表
		loadweekWeaherTable(weekWeaherDate);
 }
 
function loadweekWeaherTable(weekWeaherDate){
	//计算table列宽
	var rowNum = 5;
	var rowWidth = 0;
	rowWidth = ((100-5.4)/(1+rowNum));	
	var zhouyi=weekWeaherDate.zhouyi;
	var zhouer=weekWeaherDate.zhouer;
	var zhousan=weekWeaherDate.zhousan;
	var zhousi=weekWeaherDate.zhousi;
	var zhouwu=weekWeaherDate.zhouwu;
	var zhouliu=weekWeaherDate.zhouliu;
	var zhouri=weekWeaherDate.zhouri;
	var array=new Array();
	array[0]= "<tr><th class='xykongbai'></th><th class='xyxuhao'>序号</th><th style='width: "+rowWidth+"%;'>星期</th>" +
			"<th style='width: "+rowWidth+"%;'>晴</th><th style='width: "+rowWidth+"%;'>阴</th><th style='width: "+rowWidth+"%;'>雨</th>" +
			"<th style='width: "+rowWidth+"%;'>雪</th><th class='xykongbai'></th></tr>";
	array[1]="<tr><td class='xykongbai'></td><td class='xyxuhao'>1</td><td>星期一</td>";
	array[2]="<tr><td class='xykongbai'></td><td class='xyxuhao'>2</td><td>星期二</td>";
	array[3]="<tr><td class='xykongbai'></td><td class='xyxuhao'>3</td><td>星期三</td>";
	array[4]="<tr><td class='xykongbai'></td><td class='xyxuhao'>4</td><td>星期四</td>";
	array[5]="<tr><td class='xykongbai'></td><td class='xyxuhao'>5</td><td>星期五</td>";
	array[6]="<tr><td class='xykongbai'></td><td class='xyxuhao'>6</td><td>星期六</td>";
	array[7]="<tr><td class='xykongbai'></td><td class='xyxuhao'>7</td><td>星期日</td>";
	for(var i=0;i<4;i++){
		var zhouyit = (addKannma(zhouyi[i]))==""?"0":(addKannma(zhouyi[i]));
		var zhouert = (addKannma(zhouer[i]))==""?"0":(addKannma(zhouer[i]));
		var zhousant = (addKannma(zhousan[i]))==""?"0":(addKannma(zhousan[i]));
		var zhousit = (addKannma(zhousi[i]))==""?"0":(addKannma(zhousi[i]));
		var zhouwut = (addKannma(zhouwu[i]))==""?"0":(addKannma(zhouwu[i]));
		var zhouliut = (addKannma(zhouliu[i]))==""?"0":(addKannma(zhouliu[i]));
		var zhourit = (addKannma(zhouri[i]))==""?"0":(addKannma(zhouri[i]));
		array[1]=array[1]+"<td>"+zhouyit+"</td>"
		array[2]=array[2]+"<td>"+zhouert+"</td>"
		array[3]=array[3]+"<td>"+zhousant+"</td>"
		array[4]=array[4]+"<td>"+zhousit+"</td>"
		array[5]=array[5]+"<td>"+zhouwut+"</td>"
		array[6]=array[6]+"<td>"+zhouliut+"</td>"
		array[7]=array[7]+"<td>"+zhourit+"</td>"
		if(i==3){
			array[1]=array[1]+"<td></td></tr>"
			array[2]=array[2]+"<td></td></tr>"
			array[3]=array[3]+"<td></td></tr>"
			array[4]=array[4]+"<td></td></tr>"
			array[5]=array[5]+"<td></td></tr>"
			array[6]=array[6]+"<td></td></tr>"
			array[7]=array[7]+"<td></td></tr>"
		}
	}	
	var strTr="";
	for(var i=0;i<array.length;i++){
		strTr=strTr+array[i];
	}
	var html="<table  class='indextable xyliebiao widthall' id=\"tableOut1\">"+strTr+"</table>";
	$("#hdtable3").val(html);
	$("#weekWeatherGraphtable").html(html);
}
 
function loadChartTable(tubiaoDate){
	//计算table列宽
	var rowNum = 5;
	var rowWidth = 0;
	rowWidth = ((100-5.4)/(1+rowNum));
	
	
	var avgList=tubiaoDate.avgList;
	var WeekList=tubiaoDate.WeekList;
	var workList=tubiaoDate.workList;
	var array=new Array();
	array[1]= "<tr><th class='xykongbai'></th><th class='xyxuhao'>序号</th><th style='width: "+rowWidth+"%;'>类型</th><th style='width: "+rowWidth+"%;'>晴</th><th style='width: "+rowWidth+"%;'>阴</th><th style='width: "+rowWidth+"%;'>雨</th><th style='width: "+rowWidth+"%;'>雪</th>";
	array[2]="<tr><td class='xykongbai'></td><td class='xyxuhao'>1</td><td>工作日</td>";
	array[3]="<tr><td class='xykongbai'></td><td class='xyxuhao'>2</td><td>节假日</td>";
	array[4]="<tr><td class='xykongbai'></td><td class='xyxuhao'>3</td><td>日平均</td>";
	for(var i=0;i<4;i++){
		var work = (addKannma(workList[i]))==""?"0":(addKannma(workList[i]));
		var Week = (addKannma(WeekList[i]))==""?"0":(addKannma(WeekList[i]));
		var avg = (addKannma(avgList[i]))==""?"0":(addKannma(avgList[i]));
		array[2]=array[2]+"<td>"+work+"</td>"
		array[3]=array[3]+"<td>"+Week+"</td>"
		array[4]=array[4]+"<td>"+avg+"</td>"
		if(i==3){
			array[1]=array[1]+"<th class='xykongbai'></th></tr>"
			array[2]=array[2]+"<td></td></tr>"
			array[3]=array[3]+"<td></td></tr>"
			array[4]=array[4]+"<td></td></tr>"
		}
	}	
	var strTr="";
	for(var i=1;i<array.length;i++){
		strTr=strTr+array[i];
	}
	var html="<table class='indextable xyliebiao widthall' id=\"tableOut2\">"+strTr+"</table>";
	$("#hdtable1").val(html);
	$("#ChartTable").html(html);
}
 
 function loadpieGraph(pieData,stadubiao,endtubiao,siteN){
	 var tit = "数据说明："+siteTypeName+"天气分布"+"\n"
			+"时间范围："+stadubiao+(endtubiao==null?'':"~"+endtubiao)+"\n"
			+"场所名称："+siteN;
	 var width = $("#weekWeatherGraph").width();
	var height = $("#weekWeatherGraph").height();
//	var titleOffens = width*7.6/100;
	var titleOffens = 25;
	var dataZoomY = height*(1-19/100);
	var toolboxX = width*81.5/100;
	var legendY = height*4/100;
	var toolboxY = height*4/100;
	titContext = tit;
	//获取当前时间
	var date = new Date;
	var today = timeFormat(date);
	
	var sunnyTimesNum = parseInt(pieData.sunnyTimes);
	var cloudyTimesNum = parseInt(pieData.cloudyTimes);
	var rainTimesNum = parseInt(pieData.rainTimes);
	var snowTimesNum = parseInt(pieData.snowTimes);
	var total = sunnyTimesNum+cloudyTimesNum+rainTimesNum+snowTimesNum;
	var tolalper = (parseFloat((sunnyTimesNum/total*100).toFixed(2))+parseFloat((cloudyTimesNum/total*100).toFixed(2))+parseFloat((rainTimesNum/total*100).toFixed(2))+parseFloat((snowTimesNum/total*100).toFixed(2))).toFixed(2);
	var totaldis = parseFloat(tolalper) - 100; 
	//保存图片的名称
	var toolboxName = $("#titles").val()+'-天气分布'+today;
	 var dateStr="{value:"+pieData.sunnyTimes+", name:'晴'},{value:"+pieData.cloudyTimes+", name:'阴'},{value:"+pieData.rainTimes+", name:'雨'},{value:"+pieData.snowTimes+", name:'雪'},";
	 var data = eval("["+dateStr+"]");
	 var myChart = echarts.init(document.getElementById("historyWeatherGraph"));
	 var option = {
				 title : {
			      text: titContext,
			      y:'bottom',
			      x:titleOffens,
			      textStyle:{
			        fontSize: 12,
	   		        color: '#666',
					fontFamily:'微软雅黑, 兰亭细黑, 宋体',
	   		        fontWeight:'normal'
			    	}		
	 			},
			     tooltip: {
   				trigger: 'item',
				formatter: function(params, ticket, callback){
						console.log(params);
						var b = params[1];
						var c = params[2];
						var d =	params[3];
						var f = params[7];
						if(f==1){
							d = (parseFloat(d) - totaldis).toFixed(2);
						}
						return b+":"+c+"("+d+"%)";
					}
   				},
//			{
//			        trigger: 'item',
//			        formatter: "{b} : {c} ({d}%)"
//			    },
			    legend: {
//			    	y:legendY,
			        orient : 'vertical',//布局方式，默认为水平布局，可选为：'horizontal' | 'vertical'
			        x : titleOffens,//水平安放位置，默认为全图居中，可选为：'center' | 'left' | 'right' | {number}（x坐标，单位px）
			        data:['晴','阴','雨','雪'],
			    },
			    toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            magicType : {show: true, type: ['line', 'bar']},
			            restore : {show: true},
			            saveAsImage : {show: true,name:toolboxName}
			        },
			        x:toolboxX,
//			        y:toolboxY
			    },
			    calculable : true,
			    series : [
			        {
			            type:'pie',
			            radius : '55%',
			            center: ['50%', '50%'],
			            data:data
			        }
			    ]
			};
	 
	//改变窗口大小使图标自适应窗口显示
		window.onresize = function () {
			myChart.resize();
		}
	 myChart.setOption(option);
 }
 
 
 function loadStripeTable(xsis,dateStr1,dateStr2){
	 
		var head="<table class=\"datatable\" id=\"tableOut3\"  cellpadding=\"0\" cellspacing=\"0\">";	
		
		var titlehead="<tr>"
			var titleTr="<th>日期类型/周</th>"
			for(var i=0;i<xsis.length;i++){
				titleTr=titleTr+"<th>"+xsis[i]+"</th>";
			}
		var titlefoot="</tr>"
		
			
		var gongzuorihead="<tr>"
			var gongzuoriTr="<td>工作日</td>"
				for(var i=0;i<dateStr1.length;i++){
					gongzuoriTr=gongzuoriTr+"<td>"+dateStr1[i]+"</td>";
				}
		var gongzuorifoot="</tr>"
				 
		var zhourihead="<tr>"
			var zhouriTr="<td>周末</td>"
				for(var i=0;i<dateStr2.length;i++){
					zhouriTr=zhouriTr+"<td>"+dateStr2[i]+"</td>";
				}
		var zhourifoot="</tr>"
		var foot="</table>"
		var html=head+titlehead+titleTr+titlefoot+gongzuorihead+gongzuoriTr+gongzuorifoot+zhourihead+zhouriTr+zhourifoot+foot;
	    $("#stripegraphtable").html(html);

	 
	 
 }
	//导出Excle
	function outWeatherCSV() {
		var fileName = $("#biaogeshuoming").html();
		var type = $("#hdtype").val();
		 var from = $('#startDate').val();
	     var to = $('#endDate').val();
	     var siteId= $("#siteKey").val();
	     var tubiao = "tubiao1";
	     var span = $("#txtspan").val();
//		 { from: from, to: to, from2: from2, to2: to2, type: type, span: span, siteId: siteId },
	    location.href = "getWeatherExportExcle?from="+from+"&to="+to+"&type="+type+"&span="+span+"&siteId="+siteId+"&fileName="+fileName;
	}	
	 function fromsubmit(){
			var  siteKey=$('#siteKey').val();
			$('#selectSitekey').val(siteKey);
			$('#siteSelectForm').submit();
		}